﻿using System;
using System.Collections.Generic;

namespace TShooter.TfsSearch.EngineModel
{
    public static class EngineFactory
    {
        private static readonly Dictionary<string,Type> _RegisteredEngines = new Dictionary<string, Type>();

        public static void RegisterEngine(string name, Type type)
        {
            if (!typeof(IEngine).IsAssignableFrom(type))
            {
                throw new ArgumentException(string.Format("Class {0} must implement IEngine", type.FullName), "type");
            }
            _RegisteredEngines.Add(name, type);
        }

        public static IEngine GetEngine(string name)
        {
            if (_RegisteredEngines.ContainsKey(name))
            {
                return (IEngine) Activator.CreateInstance(_RegisteredEngines[name]);
            }
            else
            {
                return null;
            }
        }
    }
}
